App.controller("guiderManagementCtrl",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	
	$scope.search = {};		//搜索参数
	$scope.form1 = {};		//导购
	$scope.form = {};       //设置任务
	$scope.form2 = {};    //人员批量处理的数据
	$scope.shopName_show = true;	//商户名称（显示）
	$scope.addGuider_show = true;	//新建导购（显示）
	$scope.setTask_show = true;		//设置任务（显示）
	$scope.shopName_hidden = false;		//商户（隐藏）
	$scope.shopBelong_show = true;		//所属店铺（显示）
	$scope.addEditshow = true;     //新增设置任务
	$scope.batchAddShow = true;   //批量新增设置任务
	$scope.shopNames = true;   //所属商户搜索框
	$scope.department = true;  //部门编号
	var alertModel = {};	//alert模态框
	var resultData = [];    //所属导购的数据
	var checkArr = [];    //批量处理任务
	var userNames = '';    //username 的
	var cityCode1 = null;    //商户区域的市
	var flag1 = null;         //时间的开关
	var falgNUms = false;    
	
	if(userInfo.user_level==0){	//开发者
		$scope.addGuider_show = false;
		$scope.setTask_show = false;
		$scope.organization = true;  //组织编号
	}else if(userInfo.user_level==3){	//三级用户
		$scope.setTask_show = false;
		$scope.organization = true;  //组织编号
		$scope.gitTypes = true; 
	}else if(userInfo.user_level==2){	//二级用户
		
		$scope.gitTypes = true;
	}else if(userInfo.user_level==1){	//一级用户
		$scope.department = false;  //部门编号
		$scope.setTask_show = false;
		$scope.shopName_show = false;
		$scope.shopName_hidden = true;   //所属商户列表的隐藏
		$scope.shopNames = false;   //所属商户搜索框
		$scope.shopBelong_show = false;
		
		$scope.gitTypes = false;
	}
	
	
	
	//表格对象
	$scope.gridOptions = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/selectUserManagePage",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var sort = [{dir:"desc",field:"create_time"}];
							if(options.sort!=null && options.sort.length>0 ){
								if(options.sort[0].field=="create_time"){
									options.sort[0].field="create_time";
								}else{
									options.sort[0].field="create_time";
								}
								
								sort=options.sort;
							}
							
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									creater_name:$scope.search.creator_name,  //创建者
									name:$scope.search.personnel_name, //人员名称
									user_name:$scope.search.personnel_account, //人员账号
									shop_name:$scope.search.belong_commercial, //所属商户
									status:$('#guiderState').val(),    //账号状态
									section_id:$('#guiderType').val(),//导购类型
									create_time_start:$('#startTime').val(),//创建时间（开始）
									create_time_end:$('#endTime').val(),//创建时间（结束）
									bmh:$scope.search.department_code,//部门编号
									zzh:$scope.search.organization_code,//组织编号
									sort:sort
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.result.data;
					},
					total : function(d) {
						return d.result.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "single"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "id", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass' value='#: id #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "sys_user_name",         
						title : "所属专卖店",     
						width : "100px",
						hidden: $scope.shopName_hidden
					},
					{
						field : "name",         
						title : "人员名称",     
						width : "100px"
					},
					{
						field : "phone",         
						title : "联系方式",     
						width : "100px"
					},
					{
						field : "creater_name",         
						title : "创建者",     
						width : "100px"
					},
					{
						field : "user_name",         
						title : "人员账号",     
						width : "100px"
					},
					{
						field : "generalize_num",         
						title : "推广数量",     
						width : "100px"
					},
					{
						field : "zzh",         
						title : "组织编号",     
						width : "100px"
					},
					{
						field : "bmh",         
						title : "部门编号",     
						width : "100px"
					},
					{
						field : "create_time",         
						title : "创建时间",     
						width : "100px",
						template: function(e){
						 return	publicService.switchTime(e.create_time,'dateTime');
						}
					},
					{
						field : "",         
						title : "修改时间",     
						width : "100px",
						template:function(e){
							if(e.update_time==null){
								return '暂未修改';
							}else{
								 return	publicService.switchTime(e.update_time,'dateTime');
							}
							
						}
					},
					{
						field : "section_name",         
						title : "导购类型",     
						width : "100px"
//						values: [
//						         { text: "推广", value: 1 },
//						         { text: "店员", value: 2 },
//						         { text: "临促", value: 3 },
//						         { text: "小区推广", value: 4 }
//				        ]
					},
					{
						field : "status",         
						title : "状态",     
						width : "100px"
					},
					{
						field : "",         
						title : "操作",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	if(userInfo.user_level == 3){
					    		if(e.isEditer){
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}else{
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',1)">查看</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}

					    	}else if(userInfo.user_level == 2){
					    		if(e.isEditer){
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}else{
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',1)">查看</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}
					    	}else if(userInfo.user_level == 1){
					    		if(e.isEditer){
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',0)">编辑</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}else{
							    	var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',1)">查看</div>'
			    						+'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
			    						+'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
							    	return template_html;
					    		}
					    	}else if(userInfo.user_level == 0){
				    			var	template_html ='<div class="operation k-state-default splitButtonTwoc" ng-click="editDetails(\''+e.id+'\',1)">查看</div>'
				    							   +'<div class="operation k-state-default splitButtonTwoc" ng-click="correlationData(\''+e.id+'\',\''+e.status+'\')">相关数据</div>'
				    							   +'<div class="operation k-state-default " ng-click="taskLooks(\''+e.id+'\')">任务查看</div>';
					    	return template_html;
				    		}

					    	if(userInfo.user_type==1){  //开发者
					    		
					    	}else if(userInfo.user_type==2){  //企业
					    		
					    	}else if(userInfo.user_type==3){  //合伙人
					    		
					    	}else if(userInfo.user_type==4){  //品牌
					    		
					    	}else if(userInfo.user_type==5){  //店铺
					    		
					    	}

					    	return html;
					    },
					}
			]
	};
	
	//查询
	$scope.search = function(){
		$scope.grid.dataSource.page(1);
	};
	//初始化省
	$scope.initProvince = function(){
		$("#province").kendoComboBox({
		    dataTextField: "name",
		    dataValueField: "code",
		    placeholder: "省",
		    filter: "contains",
		    dataSource: {
		      serverFiltering: true,
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path+"/server/province",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						return d.result;
					}
				},
	      },
	      change: function(e) {
	    	    var valueList = this.value();
	    	    provinceCode1 = valueList;
	    	    if(valueList&&valueList.length>0){
	    	    	$("#area").data("kendoComboBox").value("");
	    	    }
	    	    $scope.getCityData(valueList);
	      }
		});
	}
	
	//获取市数据
	$scope.getCityData = function(provinceCode,defaultVal){
		$http({
			   url: path+"/server/city/"+provinceCode,
			   method: 'GET'
		}).success(function(data){
			$scope.initCity(data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	$scope.initCity = function(cityData,defaultVal){
		if(cityData){
			var plugObj = $("#city").data("kendoComboBox");
			plugObj.value("");
			plugObj.setDataSource(cityData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#city").kendoComboBox({
			    dataTextField: "name",
			    dataValueField: "code",
			    placeholder: "市",
			    filter: "contains",
			    dataSource: [],
			    change: function(e) {
		    	    var value = this.value();
		    	    cityCode1 = value;
		    	    if(value&&value.length>0){
		    	    	$("#area").data("kendoComboBox").value("");
		    	    }
		    	    $scope.getAreaData(value);
		      }
			});
		}
	}
	
	//获取区数据
	$scope.getAreaData = function(cityCode,defaultVal){
		$http({
			   url: path+"/server/county/"+cityCode,
			   method: 'GET'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
		}).success(function(data){
			 areaArr = data.result;
			allAreaStr = '';
			$.each(areaArr, function(index, OneObj){
				allAreaStr += (OneObj.code+",");
			});
			if(areaArr.length == 0){  //没有区的时候传市的编码
				allAreaStr = cityCode;
			}
			var allArea = {code:"all",name:"全城"};  //全城
			areaArr.unshift(allArea);

			$scope.initArea(areaArr,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化区
	$scope.initArea = function(areaData,defaultVal){
		if(areaData){
			var plugObj = $("#area").data("kendoComboBox");
			plugObj.setDataSource(areaData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#area").kendoComboBox({
				  dataTextField: "name",
				  dataValueField: "code",
				  placeholder: "请选择区域",
				  filter: "contains",
				  dataSource: [],
				  change:function(e){
					  valueList = this.value();
					  $scope.getShopList(valueList);
					  
				  }
			});
		}
	};	
	//获取店铺列表
	$scope.getShopList = function(code){
		if(code == 'all'){
			code = cityCode1;
		}
		var paramObj = {
				code:code
		};
		
		$http({
			   url: path+'/server/selectStairShopsByUid',
			   method: 'POST',
			   data: angular.toJson(paramObj), 
		}).success(function(data){ 
			if(data.code==0){  //成功
				$scope.showGif();   
				if(data.result){
					var dataArr = [];
					$.each(data.result,function(index,objs){
						var results = {}
					console.log(index.split('_')[1]);
					results.id = index.split('_')[1];
					results.name= objs;
					dataArr.push(results);
					});
					$("#belongStore").data("kendoDropDownList").setDataSource(dataArr);
				}
				
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
	};
	//新增导购的导购类型请求
	$scope.getGiutRequest = function(){
		$http({
			   url: path+'/server/userManageDepts',
			   method: 'GET'
		}).success(function(data){ 
			if(data.code==0){  //成功
				resultData = data.result;
			}else if(data.code==1){  //失败
				console.log(data);
			}
		}).error(function(data){
			alert(data);   
		})
	};
	//获取活动列表
	$scope.getActitityList = function(id){
		$http({
			   url: path+'/server/getActivitys/'+id,
			   method: 'GET'
		}).success(function(data){ 
			if(data.code==0){  //成功
				var	resultData = data.result;
				var objs = {};
				objs.name = '请选择';
				objs.id = '';
				resultData.push(objs);
				$scope.showBelong("name","acitivity_name",resultData);
				$("#acitivity_name").data("kendoDropDownList").value(""); 
				$scope.task_starttime = "";    //开始时间
				$scope.task_endtime = "";   //结束时间
				$scope.form.activity_num = "";   //活动成绩单数
				$scope.form.customer_num = "";  //邀请客户人数
			}else if(data.code==1){  //失败
				console.log(data);
			}
		}).error(function(data){
			alert(data);   
		});
	}
	//所属店铺
	$scope.showGif = function(){
		$("#belongStore").kendoDropDownList({
		    placeholder: "暂未有专卖店选中",
		    dataSource: [],
			dataTextField: "name",
		    dataValueField: "id",
	      	change: function(e) {
	      	},
		});
	};
	//实例化下拉选择
	$scope.showBelong = function(name,stores,nameList){
		$("#"+stores).kendoDropDownList({
		    dataSource:nameList,
			dataTextField:name,
		    dataValueField: "id",
	      	change: function(e) {
	      		var values = this.value();
	      		if(stores=='acitivity_name'&&values){
	      			$http({
	     			   url: path+'/server/selectActivityTime/'+values,
	     			   method: 'GET'
	      			}).success(function(data){ 
		     			if(data.code==0){  //成功
		     				var	resultData = data.result;
		     				console.log(resultData);
		     				$scope.task_starttime =resultData.generalize_start;  //开始时间
		     					$scope.task_endtime =resultData.end_time ; // 结束时间
		     					
			     				$scope.form.task_starttime =new Date(resultData.generalize_start).getTime();  //开始时间
		     					$scope.form.task_endtime =new Date( resultData.end_time).getTime();  //开始时间  ; 
		     			}else if(data.code==1){  //失败
		     				console.log(data);
		     			}
		     		}).error(function(data){
		     			alert(data);   
		     		});
	      		}
	      	},
		});
	};
	//验证手机号
	$scope.checkPhoneNumber2 = function(value){
		var phoneStr = /^1[3|4|5|7|8]\d{9}$/; 
		if(phoneStr.test(value)){
			return true;
		}else{
			return false;
		}
	};
		
	//验证固定电话
	$scope.checkTellNumber1 = function(value){
		var tellStr = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,9})+(\-[0-9]{1,4})?$/; 
		if(tellStr.test(value)){
			return true;
		}else{
			return false;
		}
	};
	$scope.checkPhoneNumberAll = function(){
		var strs =$scope.form1.phone;
		if($scope.checkTellNumber1(strs)||$scope.checkPhoneNumber2(strs)){
			
		}else{
			alert("电话的格式不正确！请重新输入");
			$scope.form1.phone = "";
		}
	};
//	//编辑(或者查看 0 是编辑 1是查看)
	$scope.editDetails = function(id,type){
		$scope.showBelong("dept_name","guiderType_window",resultData);//实例化所属店铺
		$http({
			   url: path+'/server/selectUserManageOne/'+id,
			   method: 'GET' 
		}).success(function(data){ 
			if(data.code==0){  //成功
				var resultData = data.result;
				$scope.form1.id = id;    //导购id
				userNames = resultData.user_name;
				$scope.form1.name= resultData.name;  //邀请客户人数
				$scope.form1.phone = resultData.phone;  //电话
				$scope.form1.user_name = resultData.user_name;  //账号
				$scope.form1.user_pwd = resultData.user_pwd; //密码
				$scope.form1.weixinhao = resultData.weixinhao; //微信号
				$scope.form1.zzh = resultData.zzh; //组织编号
				$scope.form1.bmh = resultData.bmh; //部门编号
				$("#guiderType_window").data("kendoDropDownList").value(resultData.section_id);  //导购类型
//				$("#accountState").data("kendoDropDownList").value(resultData.status);  //账号状态
				var shopData = {};
				var shopDa = [];
				shopData.id= resultData.shop_id;
				shopData.name= resultData.sys_user_name;
				shopDa.push(shopData);
				$("#belongStore").data("kendoDropDownList").setDataSource(shopDa);  //所属店铺
				$("#belongStore").data("kendoDropDownList").value(resultData.shop_id);   //所属店铺
				if(type == 0){  //编辑
					$('#method').val('edit');
					$scope.passwordReset_show = true; //重置按钮显示
					$("input").removeAttr("disabled");//让所有的input变为只读
					$scope.submits = true;  //确定提交按钮显示
					$("#belongStore").data("kendoDropDownList").readonly(false);  //所属店铺
					$("#guiderType_window").data("kendoDropDownList").readonly(false);  //导购类型
//					$("#accountState").data("kendoDropDownList").readonly(false);  //账号状态
					$("#province").data("kendoComboBox").readonly(false);
					$('.noEdit').attr("disabled","true")
					
					
				}else if(type == 1){  //查看详情
					$("#province").data("kendoComboBox").value("");
					$("#city").data("kendoComboBox").value("");
					$("#area").data("kendoComboBox").value("");
					$scope.passwordReset_show = false; //重置按钮隐藏
					$('.hiddenInput').attr("disabled","true");//让所有的input变为只读
					$scope.submits = false;  //确定提交按钮不显示
					$("#belongStore").data("kendoDropDownList").readonly(true);  //所属店铺
					$("#guiderType_window").data("kendoDropDownList").readonly(true);  //导购类型
//					$("#accountState").data("kendoDropDownList").readonly(true);  //账号状态
					$("#province").data("kendoComboBox").readonly(true);
				}
				$scope.guiderWindow.center().open();
			}else if(data.code==1){  //失败
				
			}
		}).error(function(data){
			alert(data);   
		})
	};
	//相关数据
	$scope.correlationData = function(id,state){
		var params = {guideId:id,guiderState:state};
		$location.path("/generalizeData/"+angular.toJson(params));
	};
//	//任务查看
	$scope.taskLooks = function(id){
		var params = {brandId:id};
		$location.path("/taskLook/"+angular.toJson(params));
	};
	
	//提示信息
	$scope.alertMessage = function(message){
		alertModel.pannel = jqueryAlert({
			content: message,
			modal: true
		});
	}
	
	//全选，取消
	$scope.chooseAll = function(className,flag){
		publicService.chooseAllByClassName(className,flag);
	}
	
	//导出表格数据（1：筛选导出，2：选中导出）  
	$scope.downloadTableData = function(type){
		var paramObj = {};
		
		if(type==1){	//筛选导出
			paramObj = {
					page : 1, 
					pageSize : 10,
					ispage:false,
					param:{
						creater_name:$scope.search.creator_name,  //创建者
						name:$scope.search.personnel_name, //人员名称
						user_name:$scope.search.personnel_account, //人员账号
						shop_name:$scope.search.belong_commercial, //所属商户
						status:$('#guiderState').val(),    //账号状态
						section_id:$('#guiderType').val(),//导购类型
						create_time_start:$('#startTime').val(),//创建时间（开始）
						create_time_end:$('#endTime').val()//创建时间（结束）
					}
			};
		}else if(type==2){	//选中导出
			var ids = publicService.getChooseValueByClassName("recordClass");
			if(ids.length==0){
				$scope.alertMessage("请选择人员！");
				return;
			}
			
			paramObj = {
					page : 1, 
					pageSize : 10,
					param:{
						ids: ids
					}
			};
		}

		var requestUrl = path+"/server/export";		//请求路径
		var exportModule = "userManager_module";	//模块名称
		var form = $("<form method='POST' action='"+requestUrl+"' target='_self'>"
						+"<input type='hidden' name='module_code' value='"+exportModule+"'/>"
						+"<input type='hidden' name='page' value='"+angular.toJson(paramObj)+"'/>"
					+"</form>");
		console.log("【表单参数】",form.serializeArray());
	    $(document.body).append(form);
	    form.submit();	
	}
	
	//新建导购
	$scope.addGuider = function(){
		$scope.guiderWindow.center().open();
		$('#method').val('add');
		$scope.showBelong("dept_name","guiderType_window",resultData);//实例化所属店铺
		$scope.form1 ={};
		$("#belongStore").data("kendoDropDownList").value("");   //店铺回显
		$("#guiderType_window").data("kendoDropDownList").value("");  //导购类型
//		$("#accountState").data("kendoDropDownList").value("");   //账号状态
		$scope.submits = true;  //确定提交按钮显示
		$("#belongStore").data("kendoDropDownList").readonly(false);  //所属店铺
		$("#guiderType_window").data("kendoDropDownList").readonly(false);  //导购类型
//		$("#accountState").data("kendoDropDownList").readonly(false);  //账号状态
		$("input").removeAttr("disabled");//让所有的input变为只读
//		publicService.initAccountState2("accountState");		//初始化【账号状态】2
		$scope.passwordReset_show = false; //重置按钮隐藏
	}
	//验证新建的账号
	$scope.checkAccount = function(){

		if($scope.form1.user_name){
			var postData = {
					user_name:$scope.form1.user_name
			};
			$http({
				   url: path+'/server/selectUserManageName',
				   method: 'POST',
				   data: angular.toJson(postData),  
			}).success(function(data){
				if(data.message == 'true'){  //成功
					
				}else if(data.message == 'false'){  //失败
					alert("账号已存在，请重新输入！");
					$scope.form1.user_name = "";   //账号清空
				}
			}).error(function(data){
				console.log(data);   
			})
		}else{
			alert('请输入账号！');
		}
	};
	//新建导购（提交） 
	$scope.addGuiderToServer = function(){
		$scope.form1.section_id = $("#guiderType_window").data("kendoDropDownList").value();  //导购类型
//		$scope.form1.status = $("#accountState").data("kendoDropDownList").value();   //账号状态
		if($scope.shopBelong_show){
			$scope.form1.shop_id  = $("#belongStore").data("kendoDropDownList").value();   //所属店铺
		}
		$scope.checkPhoneNumberAll();  //检测电话
		var method =  $('#method').val();
		if(!$scope.form1.name){
			alert("请填写姓名！");
			return;
		}
		if(!$scope.form1.phone){
			alert("请填写联系方式！");
			return;
		}
		if(!$scope.form1.user_name){
			alert("请填写账号！");
			return;
		}
		if(method =="add" &&!$scope.form1.user_pwd){
			alert("请填写密码！");
			return;
		}
		if(!$scope.form1.section_id){
			alert("请填写导购类型！");
			return;
		}
		if(userInfo.user_level!==1&&!$scope.form1.shop_id){
			alert("请填写所属专卖店！");
			return;
		}
		var url = '';
		if($scope.form1.id){
			url = path+'/server/updateUserManageOne';
		}else{
			url = path+'/server/addUserManage';
		}
		
		$http({
			   url:url,
			   method: 'POST',   
			   data: angular.toJson($scope.form1)
		}).success(function(data){
			if(data.code==0){
				$scope.guiderWindow.center().close();
				alertModel.pannel = jqueryAlert({
					content: "操作成功！",
					modal: true
				});
				$scope.form1.id = "";
				$scope.form1.name = "";
				$scope.form1.phone = "";
				$scope.form1.user_name = "";
				$scope.form1.user_pwd = "";
				$("#belongStore").data("kendoDropDownList").setDataSource(""); 
				$("#guiderType_window").data("kendoDropDownList").value("");
//				 $("#accountState").data("kendoDropDownList").value("");
				$scope.search();
			}else{
				alertModel.pannel = jqueryAlert({
					content: "操作失败！",
					modal: true
				});
			}
		}).error(function(data){
			console.warn(data);   
		})
	};
	//重置密码
	$scope.resetPassword = function(){ 
		if($scope.form1.name){
			var postData = {
					user_name:userNames,
					id:$scope.form1.id,
					user_pwd: "888888"
			};
			$http({
				   url: path+'/server/updateUserManagePwd',
				   method: 'POST',
				   data: angular.toJson(postData),  
			}).success(function(data){
				if(data.code==0){  //成功
					alert("密码重置成功！");
					$scope.form1.user_pwd = "888888";
				}else if(data.code==1){  //失败
					alert(data.message);
				}
			}).error(function(data){
				console.log(data);   
			})
		}else{
			alert('请填写姓名后在重置！');
		}
	};

	//设置任务的提交
	$scope.submitsData = function(){
		//提示用户（批量的时候）
		var tipsNums = false;
		if($scope.recorded == 2){
			var pramObjes = {
					activity_id:$('#acitivity_name').val(), //活动id
					ids:$scope.form.ids    //客户列表的id
			};

			$http({
				   url:path+'/server/selectUerManagerTaskHint' ,
				   method: 'POST',
				   async:false,
				   data:angular.toJson(pramObjes)
			}).success(function(data){ 
				if(data.code==0){  //成功
					var tastTip1 = data.result.cunzai;  //已经参与的
					var tastTip2 = data.result.bucunzai; //未参与的
					var tipsTipsText = "是否重新选择活动？";
					if(confirm('已参与活动的人员:'+tastTip1+',将使用原任务数。'+'\n\n 未参与活动的人员:'+tastTip2+'，将使用此次任务数。'+'\n\n\n'+tipsTipsText)){
						return;
					}else{
						tipsNums = true;
						$scope.newPeople();
					}

				}else if(data.code==1){  //失败
					alert('接口报错！请联系服务人员！');
					return;
				}
			}).error(function(data){
				alert(data);   
			});
		};

		if($scope.recorded == 1||tipsNums){
			falgNUms = true;
			$scope.newPeople();
		}
	};
//点击确定（新建人员）
	$scope.newPeople = function(){
		$scope.form.activity_id = $("#acitivity_name").data("kendoDropDownList").value();
		if(!$scope.form.activity_id){
			alert("请填写活动名称！");
			return;
		}

		if(!$scope.form.activity_num){
			alert("请填写活动成绩单！") ;
			return;
		}
		if(!$scope.form.customer_num){
			alert("请填写邀请客户人数！");
			return;
		}
		var url="";
		if($scope.form.ids){
			url = path+'/server/addUerManagerTaskBatch';
		}else{
			url = path+'/server/addUerManagerTask';
		}
		$http({
			   url:url ,
			   method: 'POST',
			   async:false,
			   data:angular.toJson($scope.form)
		}).success(function(data){ 
			if(data.code==0){  //成功
				resultData = data.result;
				alertModel.pannel = jqueryAlert({
					content: "操作成功！",
					modal: true
				});
				$scope.settaskWindow.center().close();
			}else if(data.code==1){  //失败
				console.log(data);
				alertModel.pannel = jqueryAlert({
					content: "操作失败！",
					modal: true
				});
			}
		}).error(function(data){
			alert(data);   
		});
	};
	
	//设置任务
	$scope.setTask = function(){
		$location.path("/setTask");
	}

	publicService.initGuiderState("guiderState");		//初始化【导购状态】
	publicService.initGuiderType("guiderType");			//初始化【导购类型】
	publicService.initDate("startTime");	//创建时间（始）
	publicService.initDate("endTime");		//创建时间（止）
	
	$scope.initProvince();			//初始化省（参与商户）
	$scope.initCity();				//初始化市（参与商户）
	$scope.initArea();				//初始化区（参与商户）
//	publicService.initAccountState2("accountState");		//初始化【账号状态】2
	
	publicService.initTaskType("taskType");			//初始化【任务类型】
	
//	publicService.initDateTime("startTime_task_1");	//开始时间【设置任务】
//	publicService.initDateTime("endTime_task_1");	//结束时间【设置任务】
	
	$scope.showGif();//新增导购的导购类型请求
	$scope.getGiutRequest();  // 请求国际
	$scope.showBelong("name","belongStore");//实例化所属店铺
	
	
	
});